package com.facexue.miniprogram.api;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.facexue.miniprogram.utils.AjaxResult;
import com.facexue.miniprogram.utils.MinioUtils;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@CrossOrigin
@RestController
@Tag(name="minio存储接口类")
@RequestMapping("/api/minio")
public class MinioApi {
	@Autowired
	private MinioUtils minioUtils;
	
	@Operation(summary = "上传接口")
	@PostMapping("/upload")
	public AjaxResult uploadFile(@RequestParam("file") MultipartFile file ,String filename) {
		minioUtils.upload(file, filename);
		return AjaxResult.success();
	}
	
	@Operation(summary = "下载接口")
	@GetMapping("/dowload")
	public ResponseEntity downloadFile(@RequestParam("filename") String filename) {
		return minioUtils.download(filename);
	}
	
	@Operation(summary = "获取地址接口")
	@GetMapping("/getUrl")
	public AjaxResult getFileUrl(@RequestParam("filename") String filename) {
		Map map = new HashMap();
		map.put("FileUrl", minioUtils.getFileUrl(filename));
		return AjaxResult.success(map);
	}
}
